import React from "react";
import { useRef } from "react";
export default function Useref() {
  // 创建 ref 容器
  let username = useRef();

  let div = useRef();

  let getdata = () => {
    div.current.innerHTML = username.current.value;

    username.current.value = "";
  };

  return (
    <>
      <h1>学习 useRef 钩子函数</h1>
      <input type="text" ref={username} />
      <button onClick={getdata}>点击获取</button>
      <div
        style={{ width: "300px", height: "200px", border: "1px solid red" }}
        ref={div}
      ></div>
    </>
  );
}
